var province = new Array();
var city = new Array();


function selectProvince(){
	$.ajax({
		url: 'https://www.supertimor.cn/media_project/index.php/internalTravel/selectProvince',
		method: 'post',
		header: 'Content-Type: application/x-www-form-urlencoded',
		async:false,
		success: function(e) {
			e.result.forEach(function(value, index) {
				province.push(value.province);
			});
			$('#province').select({
				input: province[0],
				title: "请选择省市",
				items: province,
				onClose: function(d) {
					selectCity(d.data.values);
				}
			});
		}
	})
}

function selectCity(values){
	
	$.ajax({
		url: 'https://www.supertimor.cn/media_project/index.php/internalTravel/selectCity',
		method: 'post',
		header: 'Content-Type: application/x-www-form-urlencoded',
		async:false,
		data: {
			province: values
		},
		success: function(e) {
			city=[]
			e.result.forEach(function(value, index) {
				city.push(value.city);
			});
			$('#city').off().val("").data('weui-select',null).select({
				input: city[0],
				title: "请选择地区",
				items: city
			});
		}
	})
}

selectProvince();
selectCity(province[0])


function getNowFormatDate() {
    var date = new Date();
    var seperator1 = "-";
    var year = date.getFullYear();
    var month = date.getMonth() + 1;
    var strDate = date.getDate();
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
    }
    var currentdate = year + seperator1 + month + seperator1 + strDate;
    return currentdate;
}

function getDay(sDate,eDate) {
	var sArr = sDate.split("-");
	var eArr = eDate.split("-");
	var sRDate = new Date(sArr[0], sArr[1], sArr[2]);
	var eRDate = new Date(eArr[0], eArr[1], eArr[2]);
	var result = (eRDate-sRDate)/(24*60*60*1000);
	return result;
}
















$("#country").select({
	input: "中国",
	title: "请选择国家",
	items: ["中国", "亚洲", "非洲", "欧洲"],
	mask: true,
	onChange: function(d) {
		console.log(this, d);
	},
	onClose: function() {
		console.log("close");
	},
	onOpen: function() {
		console.log("open");
	}
});


$('#personType').select({
	input: "一类",
	title: "请选择人员类别",
	items: ["一类", "二类", "三类"],
});


$("#startPlane").val(getNowFormatDate())
$("#endPlane").val(getNowFormatDate())

$("#startPlane").calendar({
	dateFormat: 'yyyy-mm-dd',
	value: [getNowFormatDate()]
});
$("#endPlane").calendar({
	dateFormat: 'yyyy-mm-dd',
	value: [getNowFormatDate()]
});


$("#submit").click(function(){
	console.log(getDay($("#startPlane").val(),$("#endPlane").val()))
	var province=$('#province').val(),
		city=$('#city').val(),
		day=getDay($("#startPlane").val(),$("#endPlane").val()),
		type=$('#personType').val();
	location.href=`businessTravelResult.html?province=${province}&city=${city}&day=${day}&type=${type}`;
	

})
